#!/bin/bash

###################################
#  @author: deepsea
#  @develop_date:2024-04-18
#  @desc:行为日志去重入库脚本
###################################


cur_day=$(date +%Y-%m-%d)
pre_day=$(date -d'-1 day' +%Y-%m-%d)


export JAVA_HOME=/opt/apps/jdk
export BEELINE_HOME=/opt/apps/hive

hive_server_url=jdbc:hive2://doitedu:10000


sql="
INSERT INTO TABLE ods.user_action_log PARTITION(dt='${pre_day}')
SELECT
    username
    ,app_id
    ,app_version
    ,release_channel
    ,carrier
    ,net_type
    ,ip
    ,device_id
    ,device_type
    ,resolution
    ,os_name
    ,os_version
    ,latitude
    ,longitude
    ,event_id
    ,properties
    ,action_time
    ,session_id
FROM
(
    SELECT
    * ,
    row_number() over(partition by device_id,event_id,action_time ) as rn

    FROM  tmp.user_action_log
    WHERE dt='${pre_day}'
) o

WHERE rn=1;
"

${BEELINE_HOME}/bin/beeline -u ${hive_server_url} -n root -e "$sql"

if [ $? -eq 0 ]
then

echo '任务执行成功'
exit 0

else
echo '任务执行失败'
exit 1

fi


